import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class ConfigService extends BaseService<any> {
  private readonly logger = new Logger(ConfigService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * getConfig
   * 对应 PHP: ConfigService_admin::getConfig()
   * 逻辑类型: undefined - undefined
   */
  async getConfig() {
    // 基于PHP真实逻辑: getConfig
    // PHP原文: $info = (new CoreConfigService())->getConfig($this->request->defaultSiteId(), ConfigKeyDict::ADMIN_LOGIN)['value'] ?? [];         return [            ...
const info = this.coreConfigService.getConfig(this.request.defaultSiteId(), ConfigKeyDict.ADMIN_LOGIN).value || [];
        return [
            is_captcha: info.is_captcha || 0,//是否启用验证码
            is_site_captcha: info.is_site_captcha || 0,//是否启用站点验证码
            bg: info.bg || '',//平台登录端 背景
            site_bg: info.site_bg || '',//站点登录端  背景
        ];
    }

    /**
     * 注册与登录设置
     * @param data
     * @return true
     */
    async setConfig(data)
    {
        const config = [
            is_captcha: data.is_captcha || 0,//是否启用验证码
            is_site_captcha: data.is_site_captcha || 0,//是否启用站点验证码
            bg: data.bg || '',//平台登录端 背景
            site_bg: data.site_bg || '',//站点登录端  背景
        ];
        this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.ADMIN_LOGIN, config);
        return true;
    }

}
  }

  /**
   * setConfig
   * 对应 PHP: ConfigService_admin::setConfig()
   * 逻辑类型: undefined - undefined
   */
  async setConfig(data: any[]) {
    // 基于PHP真实逻辑: setConfig
    // PHP原文: $config = [             'is_captcha' => $data['is_captcha'] ?? 0,//是否启用验证码             'is_site_captcha' => $data['is_site_captcha'] ?? 0,//是否启用站点验证码 ...
const config = [
            is_captcha: data.is_captcha || 0,//是否启用验证码
            is_site_captcha: data.is_site_captcha || 0,//是否启用站点验证码
            bg: data.bg || '',//平台登录端 背景
            site_bg: data.site_bg || '',//站点登录端  背景
        ];
        this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.ADMIN_LOGIN, config);
        return true;
    }

}
  }
}
